package com.gezi.admin.module.code.tmpl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gezi.admin.module.code.tmpl.model.CodeTmplAddParamModel;
import com.gezi.admin.module.code.tmpl.model.CodeTmplEditParamModel;
import com.gezi.admin.module.code.tmpl.model.CodeTmplSearchModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author 格子软件
 * @createDate 2024/2/10 09:00
 * @contact 公众号：格子软件 微信：13716343106 邮箱：1424529270@qq.com
 */
@Slf4j
@Service
public class CodeTmplService extends ServiceImpl<CodeTmplMapper, CodeTmplEntity> {

    public Page<Map> findByPage(Page page, CodeTmplSearchModel searchVo) {
        return baseMapper.findBySearchVo(page,searchVo);
    }

    public List<Map> findByList(CodeTmplSearchModel searchVo) {
        return baseMapper.findBySearchVo(searchVo);
    }

    /**
     * 添加 - 事务
     * @param paramModel
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(CodeTmplAddParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void edit(CodeTmplEditParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void dels(String[] ids) {
        baseMapper.deleteByIds(Arrays.asList(ids));
    }

    public CodeTmplEntity findByTitle(String title) {
        return baseMapper.selectOne(Wrappers.<CodeTmplEntity>lambdaQuery().eq(CodeTmplEntity::getTextPutong,title));
    }
}